package com.example.mynewsweb.service;

import com.example.mynewsweb.dao.AdminDao;
import com.example.mynewsweb.po.Admin;
import com.example.mynewsweb.po.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AdminServiceImpl implements AdminService{
    @Autowired
    private AdminDao adminDao;

    @Override
    public Admin adminLogin(Admin admin) {
        Admin adminLog=adminDao.adminLogin(admin);
        if(adminLog.getAdminName().equals(admin.getAdminName())&&adminLog.getAdminPwd().equals(admin.getAdminPwd())){
            return adminLog;
        }else {
            throw new RuntimeException("用户名或密码错误!");
        }

    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<User> allUser() {
        return adminDao.allUser();
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<User> apply() {
        return adminDao.apply();
    }

    @Override
    public void agreeApply(User user) {
        adminDao.agreeApply(user);
    }

    @Override
    public void disagreeApply(User user) {
        adminDao.disagreeApply(user);
    }
}
